package com.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by White on 2017/5/16.
 * Email：whitelaning@qq.com
 */

public class DashedLineView extends View {

    private int height;
    private int width;

    public DashedLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(0xffFF5400);
        paint.setStrokeWidth(1);
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0, height);
        PathEffect effects = new DashPathEffect(new float[]{20, 10}, 2);
        paint.setPathEffect(effects);
        canvas.drawPath(path, paint);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        height = getMeasuredHeight();
        width = getMeasuredWidth();
    }
}
